# https://gitee.com/yueyinqiu5990/tj12413601/blob/master/assignment1/question1/monte_carlo.py
import random
from typing import Callable


def integrate_1d_from_0_to_1(
        integrand: Callable[[float], float],
        needle_count: int):
    result = 0
    for _ in range(needle_count):
        needle = random.random()
        result += integrand(needle)
    return result / needle_count


def generate_geometric_series(start: float, ratio: int):
    while True:
        yield start
        start *= ratio
